class Solution {
public:
    int divide(int dividend, int divisor)
{
    if(!divisor) {
        return INT_MAX;
    }
    if(divisor==1)
        return dividend;
    long long a = abs((long)dividend);
    long long b = abs((long)divisor);
    long long res = 0;
    while(a >= b) {
        long long c = b;
        for(int i = 0;a >= c;i++, c <<= 1) {
            a -= c;
            res += 1 << i;
        }
    }
    if(res > INT_MAX) {
        return INT_MAX;
    }
    return ((dividend ^ divisor) >> 31) ? -res : res;
}
};